//#include <stdlib.h>
//#include <avr/interrupt.h>
//
//#include "CoreC.h"
//
//#define _SPI_CMDType_Send 1
//#define _SPI_CMDType_Receive 2
//#define pinMISO 3
//
//volatile uint8_t _SPI_DataCount = 0;
//volatile uint8_t _SPI_DataSize = 0;
//volatile uint8_t _SPI_CurrentCommand = 0;
//volatile uint8_t *_SPI_Generic_DataStructure;
//volatile uint8_t *_SPI_DataStructure;
//volatile uint8_t _SPI_CMDType;
//
//uint8_t SPIDataIn;
//
//void SPISlaveSetup()
//{
  //DDRB |= (1<<pinMISO); //set MISO pin as output
  //SPCR |= _BV(SPE);  // turn on SPI in slave mode
  //SPCR |= _BV(SPIE); // turn on interrupts
//} 
//
//ISR (SPI_STC_vect)
//{
  //SPIDataIn = SPDR;
      //
  //if (!_SPI_DataCount) //get command
  //{
    //_SPI_CommandSelect();
  //} 
  //else // the rest of the data
  //{
    //switch (_SPI_CMDType)  
    //{
    //case _SPI_CMDType_Send:
      //_SPI_Slave_Send();
      //break;
          //
    //case _SPI_CMDType_Receive:
      //_SPI_Slave_Receive();
      //break;
    //}
  //}
//
  //_SPI_DataCount++;
      //
  //if (_SPI_DataCount > _SPI_DataSize) //if there is no more data to get then reset ready for next command
  //{
    //switch (_SPI_CMDType)
    //{
      //case _SPI_CMDType_Send:
        //*(_SPI_Generic_DataStructure + _SPI_DataCount -2) = 0;  //data has been sent and is now stale
      //break;
      //
      //case _SPI_CMDType_Receive:
        //*(_SPI_Generic_DataStructure + _SPI_DataCount -2) = 1;  //new data just arrived!
      //break;
    //}    
    //_SPI_DataCount = 0;
    //_SPI_DataSize = 0;
  //}
//}
//
  //
//void _SPI_CommandSelect()
//{
    //switch (SPIDataIn) //select data and command
    //{
    //case SPICMD_REQUEST_BUTTONDATA:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&buttonData;
      //_SPI_Slave_Send();
  	  //break;
//
    //case SPICMD_REQUEST_LINEDATA:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&lineSensorData;
      //_SPI_Slave_Send();
  	  //break;
//
    //case SPICMD_REQUEST_RF_STRING:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&RFInString;
      //_SPI_Slave_Send();
      //break;
      //
    //case SPICMD_REQUEST_WALLDATA:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&wallSensorData;
      //_SPI_Slave_Send();
      //break;
//
    //case SPICMD_SEND_LEDDATA:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&LEDData;
      //_SPI_Slave_Receive();
      //break;
      //
    //case SPICMD_SEND_OLED_STRING:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&OLEDString;
      //_SPI_Slave_Receive();
      //break;
      //
    //case SPICMD_SEND_RF_STRING:
      //_SPI_Generic_DataStructure = (volatile uint8_t*)&RFOutString;
      //_SPI_Slave_Receive();
      //break;
      //
    //}
//}
//
//void _SPI_Slave_Send()
//{
      //if (!_SPI_DataCount)
      //{
        //_SPI_CMDType = _SPI_CMDType_Send;
        //_SPI_CurrentCommand = SPIDataIn;
        //_SPI_DataSize = sizeof(*_SPI_Generic_DataStructure);
        //SPDR = _SPI_DataSize;
      //}
      //else
      //{
        //SPDR = *(_SPI_Generic_DataStructure + _SPI_DataCount -1);
      //}
//}
//
//void _SPI_Slave_Receive()
//{
    //switch(_SPI_DataCount)
    //{
      //case 0:
        //_SPI_CMDType = _SPI_CMDType_Receive;
        //_SPI_CurrentCommand = SPIDataIn;
        //_SPI_DataSize = 1; //we are expecting one more byte before we get the data structure
      //break;
      //case 1:
        //_SPI_DataSize = SPIDataIn;
      //break;
      //default:
         //*(_SPI_Generic_DataStructure + _SPI_DataCount -1) = SPIDataIn;
      //break;
    //}
//}
//
//